package com.into.common.csv.converters;

import com.into.common.csv.CSVConverter;

public class LabeledEnumConverter implements CSVConverter<LabeledEnum> {

	protected LabeledEnum[]	labeledEnum;

	public LabeledEnumConverter(LabeledEnum[] labeledEnum) {
		this.labeledEnum = labeledEnum;
	}

	@Override
	public LabeledEnum fromString(String value) throws Exception {
		for (LabeledEnum current : labeledEnum) {
			String label = current.getLabel();
			if (label == value || label.equals(value))
				return current;
		}
		throw new IllegalArgumentException(value);
	}

	@Override
	public String toString(LabeledEnum value) throws Exception {
		return value.getLabel();
	}

}
